package commands;

import java.util.*;

import user.User;
import messages.*;
import core.GameManager;
import core.UserManager;
import event.ListGamesReplyEventArgs;
import event.ListPlayersEventArgs;
import game.Game;
import game.Player;


/**
 * The ListGames command.
 * 
 * This command will handle ListGames messages.
 */
public class ListGamesCommand extends Command {

	
	public ListGamesCommand(Message message, User user) {
		super(message, user);
	}
	
	
	@Override
	public void execute() {
		GameManager gameManager = this.controller.getGameManager();
		Collection<Game> games = gameManager.getGames();
		List<String> gameNames = new ArrayList<String>();
		
		for (Game game : games) {
			gameNames.add(game.getName());
		}
		
		ListGamesReplyMessage replyMsg = new ListGamesReplyMessage(gameNames);
		
		// Fires the ListGamesReply event.
		this.controller.fireListGamesReplyEvent(new ListGamesReplyEventArgs(this.user.getLogin(), replyMsg));
	}
}
